
package com.xiaoma.myaudience.biz.model;

import com.xiaoma.myaudience.util.model.BaseColumnInfo;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;

/**
 * 视频信息bean. TODO 信息类都从本类扩展
 * 
 * @author wjying
 */
public class BaseVideoInfo extends BaseColumnInfo {
    public static final String TAG = "VideoInfo";
    
    /**视频ID*/
    public static final String PARAM_PID = "pid";
    /**视频标题*/
    public static final String PARAM_TITLE = "title";
    /**视频图片URL*/
    public static final String PARAM_IMG = "img";

    public String mPid;

    public String mTitle;

    public String mImgUrlPath;    
    
    @Override
    public void readFromCursor(Cursor cursor) {
        super.readFromCursor(cursor);
        int index = -1;
        if ((index = cursor.getColumnIndex(PARAM_PID)) != -1) {
            mPid = cursor.getString(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(PARAM_TITLE)) != -1) {
            mTitle = cursor.getString(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(PARAM_IMG)) != -1) {
            mImgUrlPath = cursor.getString(index);
            index = -1;
        }
    }

    @Override
    public ContentValues generateContentValues() {
        ContentValues values = super.generateContentValues();
        values.put(PARAM_PID, mPid);
        values.put(PARAM_TITLE, mTitle);
        values.put(PARAM_IMG, mImgUrlPath);
        return values;
    }

    @Override
    public void readFromJSONObject(JSONObject o) throws JSONException {
        if (o != null) {
            if (o.has(PARAM_PID))
                mPid = o.getString(PARAM_PID);
            if (o.has(PARAM_TITLE))
                mTitle = o.getString(PARAM_TITLE);
            if (o.has(PARAM_IMG))
                mImgUrlPath = o.getString(PARAM_IMG);
        }
    }
    
    @Override
    public void readFromParcel(Parcel source) {
        mPid = source.readString();
        mTitle = source.readString();
        mImgUrlPath = source.readString();  
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel paramParcel, int paramInt) {
        paramParcel.writeString(mPid);
        paramParcel.writeString(mTitle);
        paramParcel.writeString(mImgUrlPath);        
        
    }
    
    public static final Parcelable.Creator<BaseVideoInfo> CREATOR = new Creator<BaseVideoInfo>() {
        public BaseVideoInfo createFromParcel(Parcel source) {
            BaseVideoInfo info = new BaseVideoInfo();
            info.readFromParcel(source);
            return info;
        }

        public BaseVideoInfo[] newArray(int size) {
            return new BaseVideoInfo[size];
        }
    };    
}
